package demo.trueLicense;

import java.util.Arrays;
import java.util.Calendar;

/**
 * description: <br>
 * createTime: 2020/12/31 14:18 <br>
 *
 * @author zzh
 */
public class Test {
    public static void main(String[] args) {
        String subject = "ioserver";
        String privateAlias = "privateKey";
        String publicAlias = "publicCert";
        String storePass = "a123456";
        String licensePath = "D:\\licenseTest\\license.lic";
        String privateKeyStorePath = "D:\\licenseTest\\privateKeys.keystore";
        String publicKeyStorePath = "D:\\licenseTest\\publicCerts.keystore";
// 生成license需要的一些参数
        LicenseCreatorParam param = new LicenseCreatorParam();
        param.setSubject(subject);
        param.setPrivateAlias(privateAlias);
        param.setKeyPass("a123456");
        param.setStorePass(storePass);
        param.setLicensePath(licensePath);
        param.setPrivateKeysStorePath(privateKeyStorePath);
        Calendar issueCalendar = Calendar.getInstance();
        param.setIssuedTime(issueCalendar.getTime());
        Calendar expiryCalendar = Calendar.getInstance();
        expiryCalendar.set(2021, Calendar.DECEMBER, 31, 23, 59, 59);
        param.setExpiryTime(expiryCalendar.getTime());
        param.setConsumerType("user");
        param.setConsumerAmount(1);
        param.setDescription("测试");

        LicenseCheckModel licenseCheckModel = new LicenseCheckModel();
        licenseCheckModel.setCpuSerial("BFEBFBFF000806EC");
        licenseCheckModel.setIpAddress(Arrays.asList("10.238.152.44"));
        licenseCheckModel.setMacAddress(Arrays.asList("00-E1-99-01-95-B1"));
        licenseCheckModel.setMainBoardSerial("/3VJNXY2/CNCMK009B31604/");
        LicenseCreator licenseCreator = new LicenseCreator(param);
        // 生成license
        licenseCreator.generateLicense();
        LicenseVerify licenseVerify = new LicenseVerify(subject, publicAlias, storePass, licensePath, publicKeyStorePath);
        licenseVerify.installLicense();
        System.out.println(licenseVerify.verify());
    }
}
